﻿using System;
using CI.PW.Controls;
using CI.PW.Models;
using NUnit.Framework;
using CI.Organism;

namespace CI.PW.UnitTests
{
    [TestFixture]
    public class EdgeSynapseTests
    {
        /// <summary>Draw function to test</summary>
        private Controls.EdgeSynapse _es;
        private VertexModel _sourceVertexModel;
        private VertexModel _targetVertexModel;
        private SynapseIO _sourceSynapseIO;
        private SynapseIO _targetSynapseIO;

        [SetUp]
        public void Setup()
        {
            // create our mocking repositry
            _sourceSynapseIO = new SynapseIO("bindingName", "shortName", "description", Guid.NewGuid());
            _targetSynapseIO = new SynapseIO("bindingName", "shortName", "description", Guid.NewGuid());
            _sourceVertexModel = new VertexModel(_sourceSynapseIO, null);
            _targetVertexModel = new VertexModel(_targetSynapseIO, null);

        }

        // check the ctor argument checking
        #region Ctor Checking
        /// <summary>
        /// Create a edge synapse with null source
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "source")]
        public void EdgeSynapseCtorNullSourceExecption()
        {
            _es = new Controls.EdgeSynapse(null, _sourceVertexModel);
        }

        /// <summary>
        /// Create a edge synapse with null target
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "target")]
        public void EdgeSynapseCtorNullTargetExecption()
        {
            _es = new Controls.EdgeSynapse(_sourceVertexModel, null);
        }

        /// <summary>
        /// Create a edge synapse with a target that is not a IOSynapse or INeuron
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "target")]
        public void EdgeSynapseCtorTargetObjectTargetExecption()
        {
            _es = new Controls.EdgeSynapse(_sourceVertexModel, new object());
        }

        /// <summary>
        /// Create a edge synapse with a source that is not a IOSynapse or INeuron
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "source")]
        public void EdgeSynapseCtorSourceObjectExecption()
        {
            _es = new Controls.EdgeSynapse(new object(), _sourceVertexModel);
        }

        #endregion

        // check the properties(and ctor saving them)
        #region Properties Checking
        /// <summary>
        /// Check and make sure the source value we put in the consturctor is what we get out
        /// </summary>
        [Test]
        public void EdgeSynapseCtorSourceEqual()
        {
            _es = new Controls.EdgeSynapse(_sourceVertexModel, _targetVertexModel);

            Assert.AreEqual(_sourceVertexModel, _es.Source, "Source property error");
        }

        /// <summary>
        /// Check and make sure the target value we put in the consturctor is what we get out
        /// </summary>
        [Test]
        public void EdgeSynapseCtorTargetEqual()
        {
            _es = new Controls.EdgeSynapse(_sourceVertexModel, _targetVertexModel);

            Assert.AreEqual(_targetVertexModel, _es.Target, "Target property error");
        }


        #endregion

    }
}
